package com.isunland.managesystem.ui;

import android.widget.Toast;
import com.google.gson.Gson;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.CustomerRelationDepPerson;
import com.isunland.managesystem.utils.LogUtil;
import com.isunland.managesystem.utils.SharedPreferencesUtil;
import java.util.ArrayList;
import java.util.HashMap;

public class CustomerMemberDialogFragment extends BaseNetworkDialogFragment {

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();

    try {

      CustomerRelationDepPerson customerContacts =
          new Gson().fromJson(arg0, CustomerRelationDepPerson.class);

      if (customerContacts == null || customerContacts.getDataList() == null) {

        return list;
      }

      for (int i = 0; i < customerContacts.getDataList().size(); i++) {
        list.add(new CustomerDialog(customerContacts.getDataList().get(i).getStaffName(),
            customerContacts.getDataList().get(i).getId() + ""));
      }
    } catch (Exception e) {
      LogUtil.e(TAG, "Exception", e);
    }

    return list;
  }

  @Override protected void emptyToast() {

    Toast.makeText(getActivity(), R.string.notRelativePer, Toast.LENGTH_SHORT).show();
  }

  @Override public String getUrl() {

    return ApiConst.URL_STAFF;
  }

  @Override public HashMap<String, String> getparameters() {

    HashMap<String, String> params = new HashMap<String, String>();
    String id =
        SharedPreferencesUtil.getString(getActivity(), SharedPreferencesUtil.CUSTOMER_ID, "");
    params.put("curPage", "1");
    params.put("pageSize", "1000");
    params.put("blongCustomerCode", id);
    return params;
  }
}
